{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import torchvision.datasets\n",
    "from torch.utils.data import DataLoader\n",
    "from torchvision import transforms"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "test_data = torchvision.datasets.CIFAR10(root=\"./dataset\", train=False, download=True, transform=transforms.ToTensor())\n",
    "dataloader = DataLoader(test_data, batch_size=64, shuffle=True, num_workers=0, drop_last=False)\n"
   ],
   "id": "75a57250640f4d12",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-04T03:10:38.547684Z",
     "start_time": "2025-09-04T03:10:38.539610Z"
    }
   },
   "cell_type": "code",
   "source": [
    "class myModel(nn.Module):\n",
    "    def __init__(self, *args, **kwargs):\n",
    "        super(myModel, self).__init__(*args, **kwargs)\n",
    "        self.conv1 = nn.Conv2d(in_channels=3, out_channels=24, kernel_size=3, stride=1, padding=0)\n",
    "\n",
    "    def forward(self, x):\n",
    "        x = self.conv1(x)\n",
    "        return x\n",
    "\n",
    "model = myModel()\n",
    "model"
   ],
   "id": "47ee4bbf8edc58f1",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "myModel(\n",
       "  (conv1): Conv2d(3, 24, kernel_size=(3, 3), stride=(1, 1))\n",
       ")"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 19
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-04T03:13:50.696933Z",
     "start_time": "2025-09-04T03:13:29.903243Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from torch.utils.tensorboard import SummaryWriter\n",
    "writer = SummaryWriter(\"./logs\")\n",
    "epoch = 0\n",
    "for data in dataloader:\n",
    "    imgs, labels = data\n",
    "    output = model(imgs)\n",
    "    # print(imgs.shape)\n",
    "    # print(output.shape)\n",
    "    out_imgs = torch.reshape(output, (-1, 3, 30, 30))\n",
    "    print(out_imgs.shape)\n",
    "    writer.add_images(\"conv-input\", imgs, epoch)\n",
    "    writer.add_images(\"conv-output\", out_imgs, epoch)\n",
    "    epoch = epoch + 1\n",
    "\n",
    "writer.close()\n"
   ],
   "id": "4c8ce21ff9506f20",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([512, 3, 30, 30])\n",
      "torch.Size([128, 3, 30, 30])\n"
     ]
    }
   ],
   "execution_count": 22
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
